import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt


class WeatherDataAnalyzer:
    def __init__(self, humidity_file, pressure_file, temperature_file, weather_file, wind_direction_file,
                 wind_speed_file):
        self.humidity_df = pd.read_csv(humidity_file)
        self.pressure_df = pd.read_csv(pressure_file)
        self.temperature_df = pd.read_csv(temperature_file)
        self.weather_df = pd.read_csv(weather_file)
        self.wind_direction_df = pd.read_csv(wind_direction_file)
        self.wind_speed_df = pd.read_csv(wind_speed_file)

        plt.rcParams['font.family'] = 'Times New Roman'

        self.custom_palette = ['#000000', '#666666']

    def display_missing_values(self, df, title, plot=False):
        # Display missing values distribution
        print(f'Missing Values in {title} DataFrame:')
        print(df.isnull().sum())
        if plot:
            # Create a heatmap for missing values with custom palette
            sns.set_palette(self.custom_palette)
            sns.heatmap(df.isnull(), cbar=False)
            plt.title(f'Missing Values Distribution in {title} DataFrame')
            plt.show()

    def analyze_city_data(self, city_name):
        city_dataframes = {
            'humidity': self.humidity_df[city_name],
            'pressure': self.pressure_df[city_name],
            'temperature': self.temperature_df[city_name],
            'weather': self.weather_df[city_name],
            'wind_direction': self.wind_direction_df[city_name],
            'wind_speed': self.wind_speed_df[city_name]
        }

        for data_type, data_df in city_dataframes.items():
            self.display_missing_values(data_df, f'{city_name} - {data_type}')

        city_combined_df = pd.concat(city_dataframes.values(), axis=1, keys=city_dataframes.keys())
        city_combined_df['datetime'] = self.humidity_df['datetime']
        city_combined_df.to_csv(f'{city_name}.csv', index=None)
        self.display_missing_values(city_combined_df, f'{city_name} - Combined', True)
        print(city_combined_df)


if __name__ == "__main__":
    analyzer = WeatherDataAnalyzer(
        '数据集/humidity.csv',
        '数据集/pressure.csv',
        '数据集/temperature.csv',
        '数据集/weather_description.csv',
        '数据集/wind_direction.csv',
        '数据集/wind_speed.csv'
    )

    cities_to_analyze = ['Houston']  # Add more cities as needed

    for city in cities_to_analyze:
        analyzer.analyze_city_data(city)
